'use strict';
const db = uniCloud.database();
const dbCmd = db.command
exports.main = async (event, context) => {
	// 1.删除express数据库里的,但删除之前要先获取到taskid
	let express = db.collection("express");
	let t= await express.doc(event.id).get();
	let tid=t.data[0].taskId
	await express.doc(event.id).remove();
	
	// 2.删除mysend数据库数组里的
	// 首先要查询到mysend里的_id,要根据_id删除数组里的元素
	let b =await db.collection("mysend").where({taskId:tid}).get()
	let mysendid=b.data[0]._id;
	let res = await db.collection('mysend').doc(mysendid).update({
	  taskId: dbCmd.pull(tid)
	})
	
	//返回数据给客户端
	return res
};
